// ignore_for_file: library_private_types_in_public_api, use_super_parameters

import 'package:flutter/material.dart';
import 'package:flutter_basics/page/cart/cart_page.dart';
import 'package:flutter_basics/page/cate/cate_page.dart';
import 'package:flutter_basics/page/home/home_page.dart';
import 'package:flutter_basics/page/user/user_page.dart';

class TabbarPage extends StatefulWidget {
  const TabbarPage({Key? key}) : super(key: key);

  @override
  _TabbarPageState createState() => _TabbarPageState();
}

class _TabbarPageState extends State<TabbarPage> {
  // 当前激活的索引
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: IndexedStack(
          index: _currentIndex,
          children: const [HomePage(), CatePage(), CartPage(), UserPage()],
        ),
        bottomNavigationBar: BottomNavigationBar(
            currentIndex: _currentIndex,
            type: BottomNavigationBarType.fixed,
            unselectedFontSize: 12,
            unselectedItemColor: Colors.black,
            selectedFontSize: 12,
            selectedItemColor: Colors.red,
            onTap: (value) {
              setState(() {
                _currentIndex = value;
              });
            },
            items: [
              BottomNavigationBarItem(
                  label: '首页',
                  icon: Image.asset(
                    'assets/tabbar/home.png',
                    width: 32,
                    height: 32,
                  ),
                  activeIcon: Image.asset(
                    'assets/tabbar/home-active.png',
                    width: 32,
                    height: 32,
                  )),
              BottomNavigationBarItem(
                  label: '分类',
                  icon: Image.asset(
                    'assets/tabbar/cate.png',
                    width: 32,
                    height: 32,
                  ),
                  activeIcon: Image.asset(
                    'assets/tabbar/cate-active.png',
                    width: 32,
                    height: 32,
                  )),
              BottomNavigationBarItem(
                  label: '购物车',
                  icon: Image.asset(
                    'assets/tabbar/cart.png',
                    width: 32,
                    height: 32,
                  ),
                  activeIcon: Image.asset(
                    'assets/tabbar/cart-active.png',
                    width: 32,
                    height: 32,
                  )),
              BottomNavigationBarItem(
                  label: '我的',
                  icon: Image.asset(
                    'assets/tabbar/user.png',
                    width: 32,
                    height: 32,
                  ),
                  activeIcon: Image.asset(
                    'assets/tabbar/user-active.png',
                    width: 32,
                    height: 32,
                  )),
            ]));
  }
}
